home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.0 KB | 182 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: RbbrBand.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Bitmap.hpp"
-
- #ifndef RBBRBAND_H
- #include "RbbrBand.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- // ----- Parts Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfbitmap
- #endif
-
- //========================================================================================
- // class CRectRubberBand
- //========================================================================================
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::CRectRubberBand
- //-----------------------------------------------------------------------------------------
-
- CRectRubberBand::CRectRubberBand(Environment* ev, CBitmapFrame* frame, ODFacet* facet, const FW_CRect& maxRect, const FW_CPoint& zoomRatio) :
- FW_CTracker(ev, frame, facet),
- fMaxRect(maxRect),
- fZoomRatio(zoomRatio),
- fRectShape(FW_kZeroRect, FW_kFrame),
- fBitmapFrame(frame)
- {
- FW_CInk ink(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- FW_CStyle style(FW_kFixed0, FW_kAntPat);
-
- fRectShape.SetInk(ink);
- fRectShape.SetStyle(style);
- }
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::~CRectRubberBand
- //-----------------------------------------------------------------------------------------
-
- CRectRubberBand::~CRectRubberBand()
- {
- }
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::BeginTracking
- //-----------------------------------------------------------------------------------------
-
- FW_CPoint CRectRubberBand::BeginTracking(Environment* ev,
- const FW_CPoint& anchorPoint)
- {
- FW_CPoint curLoc = AlignOnPixel(anchorPoint);
-
- FW_CRect rect(curLoc, curLoc);
- fRectShape.SetRectangle(rect);
- DrawRubberBand(ev);
-
- return curLoc;
- }
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::ContinueTracking
- //-----------------------------------------------------------------------------------------
-
- FW_CPoint CRectRubberBand::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_UNUSED(previousPoint);
- FW_CPoint curLoc = AlignOnPixel(currentPoint);
-
- FW_CRect rect(anchorPoint, curLoc);
- rect.Sort();
- rect.Intersection(fMaxRect);
-
- FW_CRect shapeBounds;
- fRectShape.GetRectangle(shapeBounds);
- if (rect != shapeBounds)
- {
- DrawRubberBand(ev); // erase
- fRectShape.SetRectangle(rect);
- DrawRubberBand(ev); // draw
- }
-
- return currentPoint;
- }
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::DrawRubberBand
- //-----------------------------------------------------------------------------------------
- // I want to draw the rubberband in every facet
-
- void CRectRubberBand::DrawRubberBand(Environment* ev)
- {
- FW_CFrameFacetIterator ite(ev, fBitmapFrame);
- for (ODFacet* aFacet = ite.First(ev); ite.IsNotComplete(ev); aFacet = ite.Next(ev))
- {
- FW_CViewContext vc(ev, fBitmapFrame, aFacet);
- fRectShape.Render(vc);
- }
- }
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::EndTracking
- //-----------------------------------------------------------------------------------------
-
- FW_Boolean CRectRubberBand::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- DrawRubberBand(ev); // erase
-
- return anchorPoint != lastPoint;
- }
-
- //-----------------------------------------------------------------------------------------
- // CRectRubberBand::AlignOnPixel
- //-----------------------------------------------------------------------------------------
- // We want, what ever the zoom factor, always have the selection rectangle on a pixel boundary
-
- FW_CPoint CRectRubberBand::AlignOnPixel(const FW_CPoint& location)
- {
- FW_CPoint result = location - fMaxRect[FW_kTopLeft];
-
- result.x = result.x / fZoomRatio.x;
- result.y = result.y / fZoomRatio.y;
-
- result.x = FW_RoundedToInt(result.x);
- result.y = FW_RoundedToInt(result.y);
-
- result.x *= fZoomRatio.x;
- result.y *= fZoomRatio.y;
-
- result += fMaxRect[FW_kTopLeft];
-
- return result;
- }
-